package org.myself.meeting.controller;

import org.myself.meeting.model.*;
import org.myself.meeting.service.EmployeeService;
import org.myself.meeting.service.MeetingRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class MeetingRoomController {
    @Autowired
    MeetingRoomService mrs;
    @Autowired
    EmployeeService employeeService;

    //查看会议室
    @RequestMapping("/meetingrooms")
    @ResponseBody
    public Result meetingRooms(@RequestBody Base base) {
        return new Result(200, "success", mrs.getAllmrs());

    }

    //查看会议室详情
    @RequestMapping("/roomdetails")
    @ResponseBody
    public Result roomdetails(@RequestBody Roomdetails acc) {
        return new Result(200, "success", mrs.getMrById(acc.getRoomid()));
    }

    //修改会议室
    @RequestMapping("/updateroom")
    @ResponseBody
    public Result updateRoom(@RequestBody UpdateroomAcc acc) {
        Employee emp = employeeService.getEmpsByUsername(acc.getUsername());
        if (emp.getRole() < 1) {
            return new Result(400, "权限不够,不能修改", null);
        }
        Integer result = mrs.updateRoom(acc.getMeetingRoom(), emp);

        if (result == 1) {
            return new Result(200, "success", null);
        }
        return new Result(400, "修改失败,请联系超级管理员", null);
    }

    //添加会议室
//    @RequestMapping("/admin/addmeetingroom")
//    @ResponseBody
//    public String addMeetingRoom(){
//        return "addmeetingroom";
//    }

    //添加一个会议室
    @RequestMapping("/doaddmr")
    @ResponseBody
    public Result doAddMr(@RequestBody UpdateroomAcc acc) {
        Employee emp = employeeService.getEmpsByUsername(acc.getUsername());
        Integer result = mrs.addMr(acc.getMeetingRoom(), emp);
        if (result == 1) {
            return new Result(200, "success", null);
        }
        return new Result(400, "操作失败", null);
    }
}
